﻿; MySQLPass 安装程序脚本
; 使用Inno Setup创建专业的Windows安装程序

[Setup]
AppName=MySQLPass
AppVersion=1.0.0
AppPublisher=MySQLPass Team
AppPublisherURL=http://localhost
AppSupportURL=http://localhost/support
AppUpdatesURL=http://localhost/updates
DefaultDirName={{autopf}}\MySQLPass
DefaultGroupName=MySQLPass
OutputBaseFilename=MySQLPass-Setup-1.0.0
Compression=lzma
SolidCompression=yes
WizardStyle=modern
UninstallDisplayIcon={{app}}\src\data\mp.png
UninstallDisplayName=MySQLPass v1.0.0

[Languages]
Name: "chinese"; MessagesFile: "compiler:Default.isl"
Name: "english"; MessagesFile: "compiler:Default.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1
Name: "createpythonenv"; Description: "创建Python虚拟环境"; GroupDescription: "Python环境配置"; Flags: checked
Name: "installpython"; Description: "安装Python 3.11.5"; GroupDescription: "Python环境配置"; Flags: unchecked; 

[Files]
; 主程序文件
Source: "dist\MySQLPass\MySQLPass.exe"; DestDir: "{{app}}"; Flags: ignoreversion

; 项目文件
Source: "dist\MySQLPass\*"; DestDir: "{{app}}"; Flags: ignoreversion recursesubdirs createallsubdirs

; 安装脚本
Source: "..\build_output\setup_python_env.bat"; DestDir: "{{app}}"; Flags: ignoreversion

; README和文档
Source: "README.md"; DestDir: "{{app}}"; Flags: ignoreversion
Source: "README.en.md"; DestDir: "{{app}}"; Flags: ignoreversion

; 配置模板
Source: "src\data\config_templates\*"; DestDir: "{{app}}\src\data\config_templates"; Flags: ignoreversion recursesubdirs createallsubdirs

; Python安装程序 (如果存在)


[Icons]
Name: "{{group}}\MySQLPass"; Filename: "{{app}}\start_mysqlpass.bat"
Name: "{{commondesktop}}\MySQLPass"; Filename: "{{app}}\start_mysqlpass.bat"; Tasks: desktopicon

[Run]
; 安装完成后配置Python环境
Filename: "cmd.exe"; Parameters: "/c "{{app}}\setup_python_env.bat" "{{code:GetPythonExePath}}" "{{app}}""; Description: "配置Python环境..."; Flags: runhidden waituntilterminated; Tasks: createpythonenv

; 安装Python (如果需要)


[UninstallRun]
; 卸载时清理用户数据目录
Filename: "cmd.exe"; Parameters: "/c rmdir /s /q "%APPDATA%\MySQLPass""; Flags: runhidden

[Code]
function IsPythonInstalled(): Boolean;
var
  PythonPath: string;
begin
  Result := False;
  PythonPath := ExpandConstant('{sys}\python.exe');
  if FileExists(PythonPath) then
  begin
    Result := True;
  end;
end;

function GetPythonExePath(): string;
var
  PythonPath: string;
begin
  // 尝试从系统路径获取Python
  PythonPath := ExpandConstant('{sys}\python.exe');
  if not FileExists(PythonPath) then
  begin
    // 如果系统中没有Python，尝试使用安装的Python
    PythonPath := ExpandConstant('{pf}\Python3.11.5\python.exe');
    if not FileExists(PythonPath) then
    begin
      // 如果还是没有找到，返回空字符串
      PythonPath := '';
    end;
  end;
  Result := PythonPath;
end;